/**
 * ReportGear(2011)
 */
package com.reportgear.designer.window;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;

import net.abbp.swing.util.GuiUtils;

/**
 * 消息显示窗体
 * 
 * @version 1.0 2010-6-20
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public enum MessageWindow {
	INSTANCE;

	private JWindow window;
	private JLabel lblMessage;

	MessageWindow() {
		window = new JWindow();
		window.setLayout(new BorderLayout());
		window.setAlwaysOnTop(true);
		window.setSize(360, 40);

		JPanel container = new JPanel();
		container.setLayout(new BorderLayout());
		container.setBorder(BorderFactory.createRaisedBevelBorder());

		lblMessage = new JLabel("", JLabel.CENTER);
		container.add(lblMessage);

		GuiUtils.centerWindow(window);
		window.add(container);
	}

	/**
	 * 显示消息
	 * 
	 * @param message
	 *            消息
	 */
	public void show(final String message) {
        EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				lblMessage.setText(message);
				window.setVisible(true);
			}
		});
	}

	/**
	 * 隐藏
	 */
	public void hide() {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				window.setVisible(false);
			}
		});
	}

	public static void main(String[] args) {
		MessageWindow.INSTANCE.show("这是我的测试");
	}
}
